package com.example.woh.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.woh.entity.BO.HomeworkBO;
import com.example.woh.entity.Homework;
import com.example.woh.mapper.HomeworkMapper;
import com.example.woh.service.IHomeworkService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sail
 * @since 2023-03-24
 */
@Service
@RequiredArgsConstructor
public class HomeworkServiceImpl extends ServiceImpl<HomeworkMapper, Homework> implements IHomeworkService {

    private final HomeworkMapper homeworkMapper;

    @Override
    public List<Homework> queryByClassId(String id) {
        QueryWrapper<Homework> wrapper = new QueryWrapper<>();
        wrapper.eq("class_id", id);
        return homeworkMapper.selectList(wrapper);
    }

    @Override
    public int saveHomework(HomeworkBO homeworkBO) {
        Homework homework = new Homework();
        BeanUtils.copyProperties(homeworkBO,homework);
        homeworkMapper.insert(homework);
        return homework.getId();
    }
}
